package com.javaweb.blogcite.controller.vo;

import com.javaweb.blogcite.pojo.Blog;
import com.javaweb.blogcite.pojo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommentView {
    private String nickname;
    private String content;
    private Long createDate;
    private String avatar;
    private Integer id;
    private BlogInner blog;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class BlogInner{
        String title;
        Integer id;
    }

    public CommentView(Comment comment, Blog blog) {
        this.id = comment.getId();
        this.createDate = comment.getCreateDate();
        this.content = comment.getContent();
        this.nickname = comment.getNickname();
        this.avatar = comment.getAvatar();
        if (blog == null) {
            this.blog = null;
        } else {
            this.blog = new BlogInner();
            this.blog.setId(blog.getId());
            this.blog.setTitle(blog.getTitle());
        }
    }
}
